package com.mccken.practice.data_structure.data_05;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2023-12-31 21:36
 **/
public class MaxSlidingWindow {

	public int[] maxSlidingWindow(int[] nums, int k) {
		MonotonicQueue queue = new MonotonicQueue();

		List<Integer> list = new ArrayList<>();

		for (int i = 0; i < nums.length; i++) {
			if (i < k - 1) {
				queue.push(nums[i]);
			} else {
				queue.push(nums[i]);
				list.add(queue.max());
				queue.pop(nums[i-k+1]);
			}
		}
		
		int[] result = new int[list.size()];
		for (int i = 0; i < list.size(); i++) {
			result[i] = list.get(i);	
		}
		return result;
	}
}
